package by.grsu.pereverzev.page;

import java.util.Date;
import java.util.List;

import org.apache.wicket.extensions.markup.html.form.DateTextField;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.SubmitLink;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.PropertyModel;

import by.grsu.pereverzev.app.PereverzevWebApplication;
import by.grsu.pereverzev.dao.impl.FlightDao;
import by.grsu.pereverzev.entity.Flight;

public class FlightFindPage extends WebPage {
	
	private static String station;
	private static Date date = new Date();
	
	public FlightFindPage() {
		super();

		final Form<Flight> form = new Form<Flight>("form");
		add(form);
		
		form.add(new TextField<String>("destStation", new PropertyModel<String>(this, "station")));		
		form.add(new DateTextField("dateOfDeparture", new PropertyModel<Date>(this, "date"), "DD.mm.yy"));
		
		

		form.add(new SubmitLink("find") {
			@Override
			public void onSubmit() {
				super.onSubmit();
				System.out.println("let's find! flight="+ station+" date="+date);
				FlightDao flightDao = new FlightDao(PereverzevWebApplication.DATA_XML_FOLDER);
				List<Flight> flights = flightDao.getFlightsInDayToStation(date, station);
				System.out.println(flights);
				
				setResponsePage(new FlightListPage(flights));
			}
		});
		
		form.add(new Link("cancel") {
			@Override
			public void onClick() {
				setResponsePage(new FlightFindPage());
			}
		});
		
		
	}

}
